<template>
	<!-- 有扣分时，先填写扣分说明，再提交 
	2025 废弃
	-->
	<view>
		<scroll-view scroll-y class="page">
			<view class="" v-for="(item,index) in questionList" :key="index">
				<view class="">
					<view class="title">{{item.groupDescription}}</view>
					<view class="question-section">
						<view class="w60 question">
							<text>{{item.description}}</text>
						</view>
						<view class="w20 question">
							<text>满分:{{item.scoreDefault}}</text>
						</view>
						<view class="w20 input">
							<text>扣分:{{ item.score }}</text>							
						</view>	
					</view>
					<view>
						<input type="text" class="form-control" v-model="item.remark" placeholder="扣分说明" />
					</view>
				</view>
			</view>
			<button @click="submit" type="primary" class="btn btn-primary btn-sm m-btn" :disabled="disabled">提交</button>
			<view class="cu-tabbar-height"></view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				saveData: {},
				questionList: [],
				disabled: false,
			}
		},
		onLoad(options) {
			this.saveData = JSON.parse(decodeURIComponent(options.saveData));
			this.questionList = this.saveData.scoreRecordList;
			this.questionList.forEach(item => item.remark = ''); // 临时方案：扣分说明与问题的备注同名了，所以置空
		},
		methods: {
			submit(){
				this.disabled = true;
				uni.showLoading({
					title: '提交中，请稍候...',
					mask: true
				});
				
				this.saveData.scoreRecordList = this.questionList;
				console.log('扣分说明保存参数', JSON.stringify(this.saveData));
				
				let method = this.saveData.recordFormId ? 'PUT' : 'POST';
				
				this.$util.request(this.$api.RecordFormRestful, this.saveData, method)
					.then(res => {
						if (res.code === 200) {
							vk.toast("保存成功", "success", 1000, true, () => {
								vk.navigateTo('/pages/company/list');
							});
						} else {
							console.log('保存失败', res)
							this.disabled = false;
							this.loading = false;
							vk.alert(res.msg, '保存失败');
						}
					}).catch((err) => {
						console.log('保存异常', err)
						this.disabled = false;
						this.loading = false;
						vk.alert(JSON.stringify(err), '保存异常');
					})
			}
		}
	}
</script>

<style>
@import url("/static/css/main.css");
	/* @import url("/static/css/bootstrap.css"); */

	.page {
		height: 100vh;
		background-color: #fff;
	}

	.title {
		padding: 10upx 20upx;
		background: #1b6fb7;
		color: #ffffff;
	}

	.lan {
		padding: 10upx 20upx;
		background: #edf6fb;
	}

	.question-section {
		display: flex;
		align-items: center;
		padding: 10upx 0;
		background: #fff;
	}
	
	.question-section:nth-child(2n+1) {
		background: #edf6fb;
	}

	.question {
		padding: 10upx 20upx;
	}

	.input {
		display: flex;
		flex-direction: column;
		justify-content: space-around;
		padding-right: 20upx;
	}

	.m-btn {
		margin-top: 30upx;
		margin-bottom: 20upx;
		width: 100%;
		height: 40px;
		font-size: 18px;
		background-color: #ea8834;
		border-color: #d27a2e;
	}

	.image-list {
		display: flex;
		flex-wrap: wrap;
	}

	.image-Item {
		width: 160upx;
		height: 160upx;
		margin: 16upx;
		border-radius: 6upx;
	}
</style>
